package nzk.hssftemp;

import javax.script.ScriptException;

/**
 * nzk.hssftemp.Column's property
 *
 * @author N. Zulkarnaen (n.zulkarnaen@gmail.com)
 *         Date: 7/1/13
 *         Time: 5:03 PM
 * @version $Revision: 6 $
 */
public class ColumnProp {

    /**
     * bean object field's name, to fill detail
     */
    String field;

    /**
     * @see Format
     */
    String format;

    /**
     * show condition
     *
     * @see ScriptUtil
     */
    String condition = null;

    /**
     * check if conditions are met by an object or not.
     */
    public boolean isConditionMet(Object src)
            throws ScriptException {
        if (condition == null) return true;
        ScriptUtil.prepareScript(condition);
        for (String var : ScriptUtil.variables) {
            ScriptUtil.replaceVariable(var, ReflectUtil.getFieldValueAsString(var, src));
        }
        return ScriptUtil.evalAsBoolean();
    }

    public ColumnProp(String field, String format) {
        this.field = field;
        this.format = format;
    }

    public ColumnProp(String field, String format, String condition) {
        this.field = field;
        this.format = format;
        this.condition = condition;
    }
}
